/** @file    wXtended_WeatherInfo.cpp
 *  @author  Alessandro Polo
 *  @version $Id: wXtended_WeatherInfo.cpp 2891 2010-08-12 01:58:59Z alex $
 *  @brief
 * File containing methods for the wosh::gui::wXtended_WeatherInfo class.
 * The header for this class can be found in wXtended_WeatherInfo.h, check that file
 * for class description.
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

 #include "wXtended_WeatherInfo.h"

 #include <core/ObjectFactory.h>
 #include <framework/gui/GuiUtilities.h>

 #include "ui_wXtended_WeatherInfo.h"

 #include <QtGui/QLabel>
 #include <QtGui/QTextEdit>


using namespace std;
namespace wosh {
 namespace gui {

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_REGISTER(wosh::gui::wXtended_WeatherInfo, "wosh::gui::IWidgetSerializable", 1.0, _static_wXtended_WeatherInfo )
 WOSH_GUI_MAP(wosh::gui::wXtended_WeatherInfo, "wosh::Message", 0.0, _static_Map_wXtended_WeatherInfo )

wXtended_WeatherInfo::wXtended_WeatherInfo( QWidget* parent )
	: QWidget(parent) {

	this->m_ui = new Ui::wXtended_WeatherInfo();
	this->m_ui->setupUi(this);

	setWindowIcon( GuiUtilities::createIconFor( getSerializableType() ) );
	setWindowTitle( getSerializableType() );

	loadObject(NULL);
 }

wXtended_WeatherInfo::~wXtended_WeatherInfo() {
	delete this->m_ui;
 }

void wXtended_WeatherInfo::changeEvent(QEvent *e) {
	QWidget::changeEvent(e);
	if ( e->type() == QEvent::LanguageChange )
		this->m_ui->retranslateUi(this);
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

WRESULT wXtended_WeatherInfo::loadObject( const wosh::xtended::WeatherInfo* object ) {
	if ( object == NULL ) {
		setWindowTitle( tr("%1 [NULL]").arg(getSerializableType()) );

		this->m_ui->txtID->setText( 0 );
		this->m_ui->dtimeTS->setDateTime( QDateTime() );
		this->m_ui->spinTTL->setValue( 0 );
		this->m_ui->spinReliability->setValue( 0.0 );

		this->m_ui->txtPeriodName->setText("");
		this->m_ui->dtimePeriodStart->setDateTime( QDateTime() );
		this->m_ui->dtimePeriodEnd->setDateTime( QDateTime() );

		this->m_ui->txtCondition->setText("");
		this->m_ui->txtConditionKey->setText("");
		this->m_ui->txtConditionSummary->setText("");

		this->m_ui->spinTempCurr->setValue( 0 );
		this->m_ui->spinTempMax->setValue( 0 );
		this->m_ui->spinTempMin->setValue( 0 );

		this->m_ui->timeSunRise->setTime( QTime() );
		this->m_ui->timeSunSet->setTime( QTime() );

		this->m_ui->spinWindChill->setValue( 0 );
		this->m_ui->spinWindDirection->setValue( 0 );
		this->m_ui->spinWindSpeed->setValue( 0 );

		this->m_ui->spinAtmHumidity->setValue( 0 );
		this->m_ui->spinAtmVisibility->setValue( 0 );
		this->m_ui->spinAtmPressure->setValue( 0 );
		this->m_ui->spinAtmRising->setValue( 0 );

		return WRET_OK;
	 }
	setWindowTitle( tr("%1 #%2").arg(getSerializableType()).arg(0) );

	this->m_ui->txtID->setText( QString::number(object->getSourceID()) );
	this->m_ui->dtimeTS->setDateTime( QDateTime::fromTime_t(object->getTimeStamp()) );
	this->m_ui->spinTTL->setValue( object->getTTL() );
	this->m_ui->spinReliability->setValue( object->getReliability() );

	this->m_ui->txtPeriodName->setText( object->getPeriodName().c_str() );
	this->m_ui->dtimePeriodStart->setDateTime( QDateTime::fromTime_t(object->getPeriodStart()) );
	this->m_ui->dtimePeriodEnd->setDateTime( QDateTime::fromTime_t(object->getPeriodEnd()) );

	this->m_ui->txtCondition->setText( QString("%1 [%2]").arg(object->getCondition()).arg(object->getConditionExtra()) );
	this->m_ui->txtConditionKey->setText( object->getConditionKey().c_str() );
	this->m_ui->txtConditionSummary->setText( object->getConditionSummary().c_str() );

	this->m_ui->spinTempCurr->setValue( object->getTemperature() );
	this->m_ui->spinTempMax->setValue( object->getTemperatureHighest() );
	this->m_ui->spinTempMin->setValue( object->getTemperatureLowest() );

	this->m_ui->timeSunRise->setTime( QTime(0,0,0).addSecs(object->getSunRise()) );
	this->m_ui->timeSunSet->setTime( QTime(0,0,0).addSecs(object->getSunSet()) );

	this->m_ui->spinWindChill->setValue( object->getWindChill() );
	this->m_ui->spinWindDirection->setValue( object->getWindDirection() );
	this->m_ui->spinWindSpeed->setValue( object->getWindSpeed() );

	this->m_ui->spinAtmHumidity->setValue( object->getAtmosphereHumidity() );
	this->m_ui->spinAtmVisibility->setValue( object->getAtmosphereVisibility() );
	this->m_ui->spinAtmPressure->setValue( object->getAtmospherePressure() );
	this->m_ui->spinAtmRising->setValue( object->getAtmosphereRising() );

	return WRET_OK;
 }

WRESULT wXtended_WeatherInfo::saveObject( wosh::xtended::WeatherInfo* object ) const {
	if ( object == NULL ) return WRET_ERR_PARAM;

	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////


 }; // namespace gui
}; // namespace wosh
